using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace DocLibApp
{
	/// <summary>
	/// Show Exception In a Window
	/// </summary>
	public class ehShow : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TabControl tabControl1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		#region Constructor
		/// <summary>
		/// Create instance of exception handler shows an exception
		/// </summary>
		/// <param name="ex">System Exception</param>
		public ehShow(System.Exception ex)
		{
			InitializeComponent();

			ShowException(ex);
			this.ShowDialog();
		}
		#endregion // Constructor

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.tabControl1 = new System.Windows.Forms.TabControl();
            this.SuspendLayout();
            // 
            // tabControl1
            // 
            this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(0, 0);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(494, 305);
            this.tabControl1.TabIndex = 0;
            // 
            // ehShow
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(494, 305);
            this.Controls.Add(this.tabControl1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "ehShow";
            this.ShowInTaskbar = false;
            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Exception Handler";
            this.ResumeLayout(false);

		}
		#endregion

		private void ShowException(System.Exception ex)
		{
            System.Collections.Hashtable ht = new Hashtable();
			ht.Add("Message", ex.Message);
            ht.Add("Note", ex.HelpLink);
			ht.Add("Stack Trace", ex.StackTrace );
			ht.Add("Source", ex.Source);

			foreach (string key in ht.Keys)
			{
				TabPage tpage = new TabPage(key);
				string val = ("" + ht[key]).Trim();
				
				TextBox tb1 = new TextBox();
                tb1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
				tb1.Multiline = true;
				tb1.ReadOnly = true;
				tb1.Text = val;
				tb1.ScrollBars = ScrollBars.Vertical;
				tb1.Dock = DockStyle.Fill;
				tpage.Controls.Add(tb1);
				
				tabControl1.TabPages.Add(tpage);
			}
		}
	}
}
